/**
 * Created by yongmingwei on 16/10/28.
 */
import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    TouchableOpacity,
    Platform,
    Switch,
    Image
} from 'react-native';

var Dimensions = require('Dimensions');
var {width,height} = Dimensions.get('window');
var CommonMyCell = React.createClass({
    getDefaultProps(){
        return{
            leftIconName:'',//标题
            leftTitle:'',
            rightIconName:'',
            rightTitle:''
        }
    },
    render() {
        return (
            <TouchableOpacity activeOpacity={0.5}>
                <View style={styles.container}>
                    {/*左边*/}
                    <View style={styles.leftViewStyle}>
                        <Image source={{uri:this.props.leftIconName}} style={styles.leftImageStyle}></Image>
                        <Text style={{fontSize:16}}>{this.props.leftTitle}</Text>
                    </View>
                    {/*右边*/}
                    <View style={styles.rightViewStyle}>
                        {this.rightSubView()}
                    </View>
                </View>
            </TouchableOpacity>
        );
    },
    rightSubView(){
        return(
            <View style={{flexDirection:'row',alignItems:'center'}}>
                {this.renderRightCotent()}
                <Image source={{uri: 'icon_cell_rightArrow'}} style={{width:8, height:13, marginRight:8, marginLeft:5}}/>
            </View>
        )
    },
    renderRightCotent(){
        if (this.props.rightIconName.length == 0){
            return(
                <Text style={{color:'gray'}}>{this.props.rightTitle}</Text>
            )
        }else {
            return(
                <Image source={{uri:this.props.rightIconName}} style={{width:24,height:13}}></Image>
            )
        }
    }

});

const styles = StyleSheet.create({
    container: {
        flexDirection:'row',
        justifyContent:'space-between',
        alignItems:'center',
        backgroundColor:'white',
        height:Platform.OS == 'ios'?40:36,
        borderBottomWidth:0.5,
        borderBottomColor:'#e8e8e8'
    },
    leftViewStyle:{
        flexDirection:'row',
        alignItems:'center',
        marginLeft:8
    },
    leftImageStyle:{
        width:24,
        height:24,
        marginRight:6,
        // 圆角
        borderRadius:12
    },
    rightViewStyle:{

    }
});

module.exports = CommonMyCell;